import {
  selectAll,
  schedule
} from '@/api/schedule'

const getDefaultState = () => {
  return {

  }
}

const state = getDefaultState()

const mutations = {
  RESET_STATE: (state) => {
    Object.assign(state, getDefaultState())
  }
}

const actions = {
  // use select all role menu
  selectAll({
    commit
  }, scheduleInfo) {
    return new Promise((resolve, reject) => {
      const {
        obj,
        page,
        pageSize
      } = scheduleInfo
      selectAll({
        obj: obj,
        page: page,
        pageSize: pageSize
      }).then(response => {
        resolve(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  // use add
  schedule({
    commit
  }, scheduleInfo) {
    return new Promise((resolve, reject) => {
      const {
        userId,
        date,
        oldId
      } = scheduleInfo
      schedule({
        userId: userId,
        date: date,
        oldId: oldId
      }).then(response => {
        resolve(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
